package main

import "fmt"

type T = struct{}

func main() {
	mutex := make(chan T, 1)
	mutex <- T{}

	counter := 0

	increase := func() {
		// Lock
		<-mutex
		counter++
		// Unlock
		mutex <- T{}
	}

	increase1000 := func(done chan<- T) {
		for i := 0; i < 1000; i++ {
			increase()
		}
		done <- T{}
	}

	done := make(chan T)
	go increase1000(done)
	go increase1000(done)

	<-done
	<-done

	fmt.Println(counter)
}
